package org.binglan.youziyuepai.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.binglan.youziyuepai.entity.ActivityToImage;
import org.binglan.youziyuepai.entity.Image;
import org.binglan.youziyuepai.mapper.ActivityToImageMapper;
import org.binglan.youziyuepai.service.ActivityToImageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.binglan.youziyuepai.service.ImageService;
import org.n3r.idworker.Sid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 活动与图片多对多表 服务实现类
 * </p>
 *
 * @author sanjin
 * @since 2019-04-09
 */
@Service
public class ActivityToImageServiceImpl extends ServiceImpl<ActivityToImageMapper, ActivityToImage> implements ActivityToImageService {

    @Autowired
    ImageService imageService;

    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public Boolean saveActivityToImageBatch(List<ActivityToImage> activityToImageList, Integer activityId) {
        activityToImageList.forEach(activityToImage -> {
            activityToImage.setActivityId(activityId);
        });
        if (activityToImageList.size() == 0) {
            return true;
        }
        return saveBatch(activityToImageList);
    }

}
